import React from 'react';
import {injectIntl} from './intl';
import PropTypes from 'prop-types';
import ExcelImport from '../common/ExcelImport';
import fileTemplate from '../attachment/备件索赔分类标准导入模板.xlsx';
const basePath = fetch.basePath || '';

class FileImport extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
        };
    }

    beforeUpload = () => this.setState({loading: true});

    afterUpload = ({ok}) => {
        this.setState({
            loading: false,
        });
        if(ok)
            this.props.afterImport();
    };

    render() {
        const description = [
            this.props.intl.formatMessage({
                id: 'fileImport.step2.description1',
                defaultMessage: '总代编号、索赔分类编号、索赔分类名称 不能为空；'
            }),
        ];

        return (<React.Fragment>
            <ExcelImport
                key="import"
                template={fileTemplate}
                templateName={this.props.intl.formatMessage({
                    id: 'fileImport.templateName',
                    defaultMessage: '备件索赔分类标准导入模板'
                })}
                action={`${basePath}/afterSales/api/v1/partWarrantyCategories/import`}
                description={description}
                beforeUpload={this.beforeUpload}
                afterUpload={this.afterUpload} />
        </React.Fragment>);
    }
}


FileImport.propTypes = {
    afterImport: PropTypes.func,
    intl: PropTypes.object,
    onCancel: PropTypes.func,
};

export default injectIntl(FileImport);

